<?php
/**
 * Created by PhpStorm.
 * User: River
 * Email: river0428@gmail.com
 * Date: 2018/11/9
 * Time: 上午10:42
 */

namespace Modules\Api\Controllers;

use App\Models\Notice;
use Carbon\Carbon;

class NoticeController extends Controller
{
    public function index()
    {
        $data['items'] = [];

        $res = file_get_contents(storage_path('app/notice.txt'));

        $res = explode("\r\n", $res);
        $items = [];
        $m = 10;
        foreach ($res as $key => $item) {
            $val = explode("\t", $item);
            $items[] = [
                'id' => $key + 1,
                'content' => $val[0] . '充值了' . $val[1],
                'created_at' => Carbon::now()->subMinutes($m)->diffForHumans()
            ];
            $m += mt_rand(0,9);
        }

        $data['items'] = $items;

        /*$res = Notice::orderBy('id', 'desc')->take(100)->get();
        foreach ($res as $item) {
            $data['items'][] = [
                'id' => $item->id,
                'content' => $item->content,
                'created_at' => $item->created_at->diffForHumans(),
            ];
        }*/


        return success($data);
    }
}